import Vue from 'vue'
import VueRouter from 'vue-router'
//eg import Home from '../views/Home.vue'
import Main from '../views/Main.vue'
import HeritageIndustry from '../views/HeritageIndustry.vue'
import HeritageMuseum from '../views/HeritageMuseum.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',//主页面
    name: 'Main',
    component: Main,
    children: [

      {
        path: "/heritage/industry",//
        component: HeritageIndustry
      },

      {
        path: "/heritage/museum",//几何查询
        component: HeritageMuseum
      },

      {
        path: "/ThreeDaysW",
        component: () => import('../views/ThreeDaysW.vue')

      },
      {
        path: "/MapCheLiang",
        component: () => import('../views/MapCheLiang.vue')
      },



      // 设置
      {
        path: '/setup',
        component: () => import('../views/SetUp.vue')
      },
      // 据添加
      {
        path: '/heritage/add/:editid',
        component: () => import('../views/Heritage/HeritageAdd.vue')
      },
      // 拾取坐标位置页
      {
        path: '/get/coordinate',
        component: () => import('../views/Heritage/getCoordinate.vue')
      },



    ]

  },
  {
    path: "/heritage/login",//登陆页面
    component: () => import('../views/LoginUser.vue')
  },
  // {
  //   path: "/heritage/postUser",//登陆页面
  //   component: () => import('../views/postUser.vue')
  // },

]



const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  const username = sessionStorage.getItem('username')

  const isPre = sessionStorage.getItem('isOk')
  if (isPre === 'noPre') next('/noPre')
  if (to.path !== "/heritage/login" && to.path !== "/heritage/postUser" && username === null) next("/heritage/login");
  next();
})

export default router
